home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c
- Subject: Re: A Very Simple Socket Question
- Date: 16 Jan 1996 16:16:06 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan16111606@g7240065.bridge.bst.bls.com>
- References: <4dfgj8$6p9@nntp.ucs.ubc.ca>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: evil@unixg.ubc.ca's message of 16 Jan 1996 06:28:56 GMT
-
- In article <4dfgj8$6p9@nntp.ucs.ubc.ca> evil@unixg.ubc.ca (Peter Pan) writes:
-
- : Please help! I am a C beginner.
-
- : ======================================
- : Client:
-
- : int sd, addrlen;
- : struct sockaddr_in svaddr;
-
- : char *data;
- : data = "abcdef";
-
- : .... /* skip */
-
- : sendto(sd, data, strlen(data), 0, &svaddr, &addrlen);
-
-
- : ==========================================
- : Server:
-
- : char data;
-
- I assume this was meant to say:
- char* data;
-
- : data = (char*) malloc( 100*sizeof(char) );
-
- : recvfrom(sd2, data, sizeof(data), 0, &claddr, &addrlen);
- ^^^^^^^^^^^^
- Your problem lies here. 'data' is a pointer and the sizeof a pointer,
- obviously on your machine, is 4 bytes.
- Replace this line with:
-
- recvfrom(sd2, data, 100 * sizeof(char), 0, &claddr, &addrlen);
-
- Though the multiplication of sizeof(char) is unnecessary as by definition
- this is 1.
-
- Hope this helps
-
- -A.
-
- --
- | A.Champion |
-